package com.avit.tv.kui.list;

import android.view.View;
import com.avit.tv.kui.utils.Log;

import java.lang.reflect.Field;

/**
 * 基类的Holder
 * @author like
 * @date 2020/7/2
 */
public class AvitHolder {

    private final View contentView;

    AvitHolder(View contentView){
        this.contentView = contentView;
        contentView.setTag(this);
    }

    public void initViews(Object o) {
        Field[] fields = o.getClass().getDeclaredFields();
        try {
            for (Field field : fields) {
                field.setAccessible(true);
                HolderView annotation = field.getAnnotation(HolderView.class);
                if (annotation != null) {
                    int id = annotation.id();
                    field.set(o, contentView.findViewById(id));
                }
            }
        } catch (IllegalAccessException e) {
            Log.e(this, e.getMessage());
            e.printStackTrace();
        }
    }
}
